<template>
	<div class="homeusercard">
		<div class="cardiv" @click="myshaoyishao">
			<img src="../../../static/image/img_saoyisao.png" />
			<!--<i class="icon njfont nj-saoyisao cardivimg"></i>
			<span>扫一扫</span>-->
		</div>
		<div class="cardiv" @click="myusercard">
			<img src="../../../static/image/img_usercard.png" />
			<!--<i class="icon njfont nj-huiyuanqia cardivimg"></i>
			<span>会员卡</span>-->
		</div>
	</div>
</template>

<script>
	import { MessageBox } from '@/ui-components';
	import { QCodePlugin } from '../../utils/WXH/scan.js';
	import { mapGetters } from "vuex";
	import { Toast } from "../../utils/toast.js";
	import axios from "axios";
	export default {
		props: {
			dataList: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {
				scanType: null,
				flag: true
			}
		},
		components: {

		},
		methods: {
			myusercard() {
				var sessionId = localStorage.getItem('sessionId');
				if(!this.login || !sessionId || sessionId == 'undefined') {
					MessageBox('用户未登录账号', '请先登录账号再查看会员卡').then(
						() => {
							this.$router.push({
								path: 'login',
								query: {
									page: 'home',
									Page: 1
								}
							})
						}
					)
					return
				} else {
					this.$router.push({
						path: 'code',
						query: {
							page: 'home',
							Page: 1
						}
					})
				}

			},
			myshaoyishao() {
				var sessionId = localStorage.getItem('sessionId');
				if(!this.login || !sessionId || sessionId == 'undefined') {
					MessageBox('用户未登录账号', '请先登录账号再使用扫一扫').then(
						() => {
							this.$router.push({
								path: 'login',
								query: {
									page: 'home',
									Page: 1
								}
							})
						}
					)
					return
				}
				let url = window.api.base_host + '/baseConfig/findByCode';
				let options = {
					method: "get",
					url,
					headers: {
						sessionId: sessionId
					}
				}
				if(!this.flag) {
					return
				}
				this.flag = false
				axios(options).then(data => {
					this.flag = true
					if(data.data.returnCode == 1) {
						this.scanType = data.data.data[0].scanType
						QCodePlugin(this, this.scanType);
					} else {
						Toast({
							duration: 2000,
							message: data.data.msg || '服务器数据异常',
							type: "fail"
						})
					}
				}).catch(err=>{
					Toast({
						duration: 2000,
						message: err.toString().slice(0,10) || '扫一扫请求失败',
						type: "fail"
					});
				})
			}
		},
		computed: {
			...mapGetters('wxh', [
				'login',
			]),
		},
		watch: {

		},
		mounted() {

		},
	}
</script>

<style>
	.homeusercard {
		background-color: #fff;
		padding: 0rem 0.65rem;
	}
	
	.cardiv {
		display: inline-block;
		width: 49%;
		padding: 0rem 0.1rem;
		/*margin: 0rem 0.1rem;*/
		/* height: 3.25rem; */
	}
	
	.cardivimg {
		margin-top: 0.3rem;
		margin-bottom: 0.2rem;
		display: block;
		font-size: 2rem;
	}
</style>